package corba;

import helloworld.Hello;
import helloworld.HelloHelper;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

public class HelloClient {
	public static void main(String args[]) {
		try {
			// 根据端口创建ORB实例
			String str[] = { "-ORBInitialPort", "1050" };
			ORB orb = ORB.init(str, null);
			org.omg.CORBA.Object objRef = orb
					.resolve_initial_references("NameService");

			// 获取一个指向命名上下文的引用
			NamingContext ncRef = NamingContextHelper.narrow(objRef);
			NameComponent nc = new NameComponent("Hello", "");
			NameComponent path[] = { nc };
			
			// 查找Hello对象
			Hello hello = HelloHelper.narrow(ncRef.resolve(path));
			
			// 调用函数
			String show = hello.sayHello("World");
			System.out.println(show);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
